Prune orphaned CSS artifacts before building - #471
Conversation
|
There was a problem hiding this comment.
Pull request overview
This PR ensures CSS builds start from a clean slate by removing previously generated CSS artifacts that no longer correspond to any .pcss source (e.g., after component renames/removals). This prevents script/export-css-selectors from globbing stale .css files and incorrectly polluting static/classes.json, and avoids leaving the working tree dirty after running the build.
Changes:
- Add a pre-build prune step in
build_cssto delete generated.css,.css.map, and.css.jsonfiles underapp/components/primerbefore regenerating assets.
|
| # Remove previously generated CSS artifacts so components that were renamed or | ||
| # removed don't leave orphaned files behind. Stale .css would otherwise be | ||
| # picked up by export-css-selectors and pollute static/classes.json. |
Renamed or removed components left behind generated .css files with no .pcss source (e.g. open_project/skeleton_box, open_project/tree_view). export-css-selectors globbed all .css and mapped the stale selectors into static/classes.json, leaving the working tree dirty after a build. Adds a prune step at the start of build_css that deletes the generated .css/.css.map/.css.json artifacts before regenerating from the current .pcss sources. All such artifacts are gitignored and regenerable.
The prune step removes orphaned .css before a build, but export-css-selectors itself still mapped any stray .css it globbed into static/classes.json -- so a leftover file, or running the script directly, could re-introduce dead component selectors. Filters the glob to .css that still have a sibling .pcss for folders generated from .pcss (app/components/primer). Hand-authored stylesheets under app/lib/primer/css have no .pcss and are left untouched via a requireSource flag, so their per-file json keeps generating.
3e80bfd to
88f1e2b
Compare
What are you trying to accomplish?
script/build-assetsleft the working tree dirty after a clean build. Renamed or removed components leave behind generated.cssfiles with no.pcsssource (e.g.open_project/skeleton_box,open_project/tree_view), andexport-css-selectorsglobs every.css— so the stale selectors got mapped intostatic/classes.json.Two complementary changes:
export-css-selectors) — for folders generated from.pcss(app/components/primer), skips any.csswithout a sibling.pcss, so dead component selectors never reachstatic/classes.jsonregardless of tree state or how the script is invoked. Hand-authored stylesheets underapp/lib/primer/csshave no.pcssand are left untouched via arequireSourceflag.build_css) — prunes generated.css/.css.map/.css.jsonartifacts before regenerating, so orphans don't linger in the tree.Integration
None — build-tooling change only.
List the issues that this change affects.
Build hygiene fix surfaced while working on TypeScript 6.0 (#470).
Risk Assessment
What approach did you choose and why?
Fixed the correctness bug at its source — the generator now treats the
.pcssas the source of truth (.pcssexists ⇔ component exists), sostatic/classes.jsonstays correct even if a stale.cssreappears or the script runs standalone. The prune is kept as tree hygiene to clear the orphaned artifacts. Both are safe: every.css/.css.map/.css.jsonunderapp/components/primeris gitignored and regenerated each build.Anything you want to highlight for special attention from reviewers?
Build-tooling only — no component or runtime change. Verified: the generator filter alone keeps
static/classes.jsonclean with an orphan present (and still emits the hand-authoredapp/lib/primer/cssjson), and a fullscript/build-assets cssleaves the tree clean.Merge checklist